package leetcode.median;

import java.util.Deque;
import java.util.LinkedList;
import java.util.List;

public class $491_FindSubsequences {

    List<List<Integer>> res = new LinkedList<>();

    LinkedList<Integer> path = new LinkedList<>();

    public List<List<Integer>> findSubsequences(int[] nums) {
        if (nums == null || nums.length == 0) {
            return res;
        }
        dfs(0, nums, -101);
        return res;
    }

    private void dfs(int curIndex, int[] nums, int lastValue) {
        if (curIndex == nums.length) {
            if (path.size() > 1) {
                res.add(new LinkedList<>(path));
            }
            return;
        }

        if (nums[curIndex] >= lastValue) {
            path.addLast(nums[curIndex]);
            dfs(curIndex + 1, nums, nums[curIndex]);
            path.removeLast();
        }
        if (nums[curIndex] != lastValue) {
            dfs(curIndex + 1, nums, lastValue);
        }
    }
}
